﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using Digitalmes.Model;
using Digitalmes.Model.EquipmentManagement;

namespace Digitalmes.Model.EquipmentManagement
{
    /// <summary>
    /// 维护记录
    /// </summary>
	[Table("MaintenanceRecord")]

    [Display(Name = "_Model.MaintenanceRecord")]
    public class MaintenanceRecord : BasePoco,IPersistPoco,ITenant
    {
        [Key]
        [Display(Name = "_Model._MaintenanceRecord._ID")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public new long ID { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Plan")]
        [Comment("关联计划")]
        public MaintenancePlan Plan { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Plan")]
        [Comment("关联计划")]
        public long? PlanId { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Equipment")]
        [Comment("关联设备")]
        public Equipment Equipment { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Equipment")]
        [Comment("关联设备")]
        public long? EquipmentId { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Maintainer")]
        [Comment("维护人员")]
        [NotMapped]
        public FrameworkUser Maintainer { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Maintainer")]
        [Comment("维护人员")]
        public string MaintainerId { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._MaintenanceTime")]
        [Comment("维护时间")]
        public DateTime? MaintenanceTime { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._FinishTime")]
        [Comment("完成时间")]
        public DateTime? FinishTime { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._ActualHours")]
        [Comment("实际工时(小时）")]
        [Precision(18,2)]
        public decimal? ActualHours { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Result")]
        [Comment("维护结果")]
        public MaintenanceResultEnum? Result { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Note")]
        [Comment("备注")]
        public string Note { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._Files")]
        [Comment("维护附件")]
        public List<MaintenanceRecordFiles> Files { get; set; }
        [Display(Name = "_Model._ConsumableUsage._Record")]
        [InverseProperty("Record")]
        public List<ConsumableUsage> ConsumableUsage_Record { get; set; }
        [Display(Name = "_Model._MaintenanceRecord._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

	}
    public class MaintenanceRecordFiles : TopBasePoco, ISubFile
    {
        public long MaintenanceRecordId { get; set; }
        public MaintenanceRecord MaintenanceRecord { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
